<?php
/**
 * Created by PhpStorm.
 * User: zhang-hong
 * Date: 2017/3/27
 * Time: 16:43
 * 批量体征查询
 */
class GettizhengbatchdataController extends Yaf_Controller_Abstract
{

    public function IndexAction()
    {
        $request = $this->getRequest();
        $batch_id = $request->getPost("batch_id","");
        $zhuyuan_id = $request->getPost("zhuyuan_id",0);
        $yiyuan_id = $request->getPost("yiyuan_id","");
        //医院id判断
        if($yiyuan_id === "")
        {
            Utility::apiJsonError(20028, '请输入医院ID');
        }
        elseif(!ctype_digit("$yiyuan_id"))
        {
            Utility::apiJsonError(20027, '医院ID必须是整型');
        }
        //批量id判断
        if($batch_id === "" )
        {
            Utility::apiJsonError(20060, '批量ID为空');
        }
        elseif(!ctype_digit("$batch_id"))
        {
            Utility::apiJsonError(20061, '批量ID必须是整型');
        }


        $zhuyuan_tizheng = DB::select('a.*,c.xingming,b.zhuyuan_id,b.bingchuang_hao')
            ->from(array("zhuyuan_tizheng","a"))
            ->join(array("zhuyuan_basic_info","b"),"left")
            ->on("b.zhuyuan_id","=","a.zhuyuan_id")
            ->join(array("patient_basic_info","c"),"left")
            ->on("c.patient_id","=","b.patient_id")
            ->where("batch_id","=",$batch_id)
            ->and_where("state","=",1)
            ->and_where("a.yiyuan_id","=",$yiyuan_id);

        if($zhuyuan_id)
        {
            $zhuyuan_tizheng->and_where("a.zhuyuan_id","=",$zhuyuan_id);
        }
        $res = $zhuyuan_tizheng->execute()
            ->as_array();

        if(!empty($res))
        {
            $data['state'] = '1';
        }
        else
        {
            $data['state'] = '0';
        }
        $data['result'] = $res;
        $data['error'] = 200;
        $data['msg'] = "";
        Utility::apiJsonResultExtends($data);
    }

}